﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JVP.Infrastructure;
using System.Data.SqlClient;

namespace JVP.Middleware
{
    public class DBManager : IDBManager
    {
        SqlConnection con;
        
        #region IDBManager Members

        /// <summary>
        /// To Get the Database Connection
        /// </summary>
        /// <param name="strCon"><see cref="String"/> that holds the connection string</param>
        /// <returns><see cref="SqlConnection"/> returns the database Connection</returns>

        public System.Data.SqlClient.SqlConnection getConnection(string strCon)
        {
            con = new SqlConnection(strCon);
            con.Open();
            return con;
        }

        #endregion

        #region IDBManager Members

        /// <summary>
        /// To Get the Database Command
        /// </summary>
        /// <param name="strCon"><see cref="String"/> that holds the connection string to pass the value to getConnection function</param>
        /// <returns><see cref="SqlCommand"/> returns the database command</returns>

        public SqlCommand getCommand(string strCon)
        {
            SqlConnection Conn = getConnection(strCon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Conn;
            return cmd;
        }

        #endregion

        #region IDBManager Members

        /// <summary>
        /// To Close the Connection
        /// </summary>

        public void closeConnection()
        {
            con.Close();            
        }

        #endregion
                
    }
}
